<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
    <% String path=request.getContextPath(); String basePath=request.getScheme() + "://" + request.getServerName() + ":"
        + request.getServerPort() + path + "/" ; %>

        <!DOCTYPE html>
        <html>

        <head>
            <base href="<%=basePath%>">

            <title></title>

            <meta http-equiv="pragma" content="no-cache">
            <meta http-equiv="cache-control" content="no-cache">
            <meta http-equiv="expires" content="0">
            <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
            <meta http-equiv="description" content="This is my page">
            <!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

        </head>

        <body>
            <%@ include file="/WEB-INF/jsp/common/header.jsp" %>
                <%@ include file="/WEB-INF/jsp/common/loadDiv.jsp" %>

                    <script type="text/javascript">
                        $(function () {
                            $('#startTime').datebox('setValue', getBeforeCurrentDate30Days());
                            $('#endTime').datebox('setValue', getNowFormatDate());
                            bindgrid();
                        });
                    </script>

                    <script type="text/javascript">
                        var selectedFileList = [];//已选文件列表
                        var succsessCount = 0;//上传成功文件个数
                        var errorCount = 0;//上传失败文件个数
                        /************文件处理部分*************/


                        /**
                         *文件框改变事件
                         */
                        function changeFile() {
                            var files = $("#uploadpicker").prop("files");
                            $
                                .each(
                                    files,
                                    function (index, item) {
                                        let choiseFile = $("#checkfileList>li");
                                        if (choiseFile.length > 0) {//文件去重
                                            let count = 0;
                                            $.each(choiseFile, function (index1, item1) {
                                                if (item.name == item1.innerText) {
                                                    count++;
                                                }
                                            });
                                            if (count == 0) {
                                                if (checkFileLength(item.size)) {
                                                    if (item.name.includes('#') || item.name.includes('/') || item.name.includes('&') || item.name.includes('\\') || item.name.includes(' ')) {
                                                        alert('文件名不能包含&、斜杠、反斜杠、空格等特殊字符！');
                                                        return;
                                                    }
                                                    $("#checkfileList")
                                                        .append(
                                                            "<li class=\"fileinfo\">"
                                                            + item.name
                                                            + "<a style=\"display: none; color: red; margin-left: 10px;\" href=\"javascript:void(0)\" onclick=\"RemoveFile(this,'"
                                                            + item.name
                                                            + "')\">删除</a>"
                                                            + "</li>");
                                                    selectedFileList.push(item);
                                                    AddMoushover();
                                                }
                                            }
                                        } else {
                                            if (checkFileLength(item.size)) {
                                                if (item.name.includes('#') || item.name.includes('/') || item.name.includes('&') || item.name.includes('\\') || item.name.includes(' ')) {
                                                    alert('文件名不能包含&、斜杠、反斜杠、空格等特殊字符！');
                                                    return;
                                                }
                                                $("#checkfileList")
                                                    .append(
                                                        "<li class=\"fileinfo\">"
                                                        + item.name
                                                        + "<a style=\"display: none; color: red; margin-left: 10px;\" href=\"javascript:void(0)\" onclick=\"RemoveFile(this,'"
                                                        + item.name
                                                        + "')\">删除</a>"
                                                        + "</li>");
                                                selectedFileList.push(item);
                                                AddMoushover();
                                            }
                                        }
                                    });
                        }

                        /**
                         *    判断文件是否超过限制大小
                         * @param fileLen
                         * @returns {boolean}
                         */
                        function checkFileLength(fileLen) {
                            if (fileLen > 102400000) {
                                $.messager.alert("提示", "上传文件大小不能超过100M", "error");
                                return false;
                            }
                            return true;
                        }

                        /**
                         * //添加鼠标经过事件，鼠标划过时显示“删除”
                         * @constructor
                         */
                        function AddMoushover() {
                            $(".fileinfo").hover(function () {
                                $(this).find("a").last().css("display", "");
                            }, function () {
                                $(this).find("a").last().css("display", "none");
                            });
                        }

                        /**
                         *  移除已选择的文件
                         */

                        function RemoveFile(obj, fileId) {
                            $.messager.confirm("提示", "确认删除当前文件?", function (e) {
                                if (e) {
                                    let index = $("#checkfileList>li").index($(obj).parent());
                                    selectedFileList.splice(index, 1);
                                    $(obj).parent().remove();

                                    $.ajax({
                                        type: "post",
                                        url: 'file/deleteFile?fileId=' + fileId,
                                        success: function (data) {
                                            $.messager.alert('消息', data);
                                        },
                                        error: function (XMLHttpRequest, textStatus,
                                            errorThrown) {
                                            $.messager.alert('消息', errorThrown);
                                        }
                                    });

                                }
                            });
                        }

                        /**
                         * 取得该条数据所属的文件列表
                         * @param row
                         */
                        function getFileList(id) {
                            $.ajax({
                                type: "post",
                                url: "file/getFileList",
                                data: {
                                    fileTable: "con_visa",
                                    fileRow: id
                                },
                                success: function (data) {
                                    const dataArray = eval(data);
                                    initFile(dataArray);
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                }
                            });
                        }

                        /**
                         * 初始化该条数据的文件列表
                         * @param dataArray
                         */
                        function initFile(dataArray) {
                            $("#checkfileList").empty();
                            // 			sselectedFileNameList = [];
                            selectedFileList = [];
                            dataArray
                                .forEach(function (e, i, a) {
                                    $("#checkfileList")
                                        .append(
                                            "<li class=\"fileinfo\">"
                                            + "<a style=\" color: blue; margin-left: 30px;\" href=\"javascript:void(0)\" onclick=\"downloadFile('"
                                            + e.FILE_NAME
                                            + "','"
                                            + e.FILE_ID
                                            + "')\">"
                                            + e.FILE_NAME
                                            + "</a>"
                                            + "<a style=\"display: none; color: red; margin-left: 30px;\" href=\"javascript:void(0)\" onclick=\"RemoveFile(this,'"
                                            + e.FILE_ID + "')\">删除</a>"
                                            + "</li>");
                                    // 						sselectedFileNameList.push(e.FILE_NAME);
                                    AddMoushover();
                                });
                        }

                        // 文件下载
                        function downloadFile(fileName, fileRow) {
                            let url = 'api/file/download?id=' + fileRow
                            let xhr = new XMLHttpRequest()
                            xhr.open('GET', url, true)
                            xhr.setRequestHeader('token', localStorage.getItem('tokenSupply'));
                            xhr.setRequestHeader('userType', localStorage.getItem('userType'));
                            xhr.responseType = 'blob'
                            xhr.onload = function (data) {
                                if (this.status == 200) {
                                    let blob = this.response
                                    let reader = new FileReader()
                                    reader.readAsDataURL(blob)
                                    reader.onload = function (e) {
                                        let a = document.createElement('a')
                                        a.download = fileName
                                        a.href = e.target.result
                                        $('body').append(a)
                                        a.click()
                                        $(a).remove()
                                    }
                                } else {

                                }
                            }
                            xhr.send()
                        }
                    </script>
                    <script>
                        function del(node) {
                            $.ajax({
                                type: "delete",
                                url: 'oos/corrective/action/delete?corId=' + node.corId,
                                success: function (data) {
                                    $.messager.alert('消息', data.msg);
                                    $('#add').window('close');
                                    let dg = $('#dg');
                                    dg.datagrid('enableFilter');
                                    dg.datagrid('load');
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                }
                            });
                        }

                        function back(node) {
                            $.ajax({
                                type: "get",
                                url: 'oos/corrective/action/back?' + 'corId=' + node.corId,
                                //                dataType: "xml",
                                success: function (data) {
                                    $.messager.alert('消息', data.msg);
                                    $('#add').window('close');
                                    selectList();
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                }
                            });
                        }

                        function save(action) {
                            if (!endEditing()) {
                                return;
                            }
                            if (!$('#fm').form('validate')) {
                                $.messager.show({
                                    title: '提示',
                                    msg: '有未填写数据！',
                                    timeout: 3000,
                                    showType: 'slide'
                                });
                                return;
                            }
                            $('#supervise').datagrid('acceptChanges');
                            const supervises = $('#supervise').datagrid('getRows');
                            let model = {
                                corId: $('#corId ').val(),
                                corNum: $('#corNum').textbox('getValue'),
                                corTitle: $('#corTitle ').textbox('getValue'),
                                status: '0',
                                delFlag: '0',
                                supervises: supervises
                            };
                            saveAjax(model, action)

                        }

                        function saveAjax(model, action) {
                            let corId = model.corId
                            $.ajax({
                                type: "post",
                                dataType: "json",
                                url: 'oos/corrective/action/save',
                                data: JSON.stringify(model),
                                contentType: "application/json",
                                success: function (data) {
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                },
                                complete: function (XMLHttpRequest) {
                                    if (XMLHttpRequest.responseJSON.code != 60200) {
                                        $.messager.alert('消息', XMLHttpRequest.responseJSON.msg);
                                    } else {
                                        let result = XMLHttpRequest.responseJSON.data
                                        if ('save' == action) {
                                            $.messager.show({
                                                title: '提示',
                                                msg: XMLHttpRequest.responseJSON.msg,
                                                timeout: 3000,
                                                showType: 'slide'
                                            });
                                            let dg = $('#dg');
                                            dg.datagrid('enableFilter');
                                            dg.datagrid('load');
                                            $('#add').window('close');
                                            detailAjax(result.corId)
                                        } else {
                                            commit(result)
                                        }
                                    }
                                }
                            })
                        }

                        function commit(obj) {
                            obj.status = '1'
                            $.ajax({
                                type: "post",
                                dataType: "json",
                                url: 'oos/corrective/action/save',
                                data: JSON.stringify(obj),
                                contentType: "application/json",
                                success: function (data) {
                                    if (data.code != 60200) {
                                        $.messager.alert('消息', data.msg);
                                        selectList();
                                    } else {
                                        $.messager.alert('消息', data.msg);
                                        selectList();
                                        $('#add').window('close');
                                    }
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                }
                            })
                        }

                        /**
                         * 保存附件
                         */
                        function saveAttch(row, rowId, action) {
                            let saveNum = 0
                            if (selectedFileList.length > 0) {
                                $.each(selectedFileList, function (index, item) {
                                    showFilediv();
                                    var dataform = new FormData();
                                    dataform.append("file", item);
                                    var xmlhttp = null;
                                    if (window.XMLHttpRequest) {// code for all new browsers
                                        xmlhttp = new XMLHttpRequest();
                                    } else if (window.ActiveXObject) {// code for IE5 and IE6
                                        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                                    }
                                    if (xmlhttp != null) {
                                        xmlhttp.open("POST", "api/file/springUpload?fileRow=" + rowId
                                            + "&fileTable=con_visa&fileName="
                                            + item.name, true);
                                        xmlhttp.setRequestHeader('token', localStorage.getItem('token'));
                                        xmlhttp.setRequestHeader('userType', localStorage.getItem('userType'));
                                        xmlhttp.send(dataform);
                                        xmlhttp.onreadystatechange = callbackMethods;
                                    } else {
                                        alert("你的浏览器版本不兼容，请使用更高版本的浏览器");
                                    }

                                    function callbackMethods() {
                                        if (xmlhttp.readyState == 4) {
                                            if (xmlhttp.status == 200) {
                                                saveNum += 1
                                                if (saveNum == selectedFileList.length) {
                                                    hideFilediv();
                                                    if ('1' == action) {
                                                        commit(row)
                                                    } else {
                                                        $.messager.alert('消息', '保存成功！');
                                                        selectList();
                                                        $('#add').window('close');
                                                    }
                                                }
                                            }
                                        } else {
                                            if (xmlhttp.status == 500) {
                                            }
                                        }
                                    }
                                });
                            } else {
                                if ('1' == action) {
                                    commit(row)
                                } else {
                                    $.messager.alert('消息', '保存成功！');
                                    selectList();
                                    $('#add').window('close');
                                }
                            }
                        }

                        function editrow(row) {
                            //编辑用户
                            var row = $('#dg').datagrid('getSelected');
                            if (row) {
                                $('#add').window('open');
                                $('#fm').form('load', row);
                                initBtn(row.status);

                            } else {
                                $.messager.alert('消息', '请选中一条数据');
                            }
                        }
                    </script>
                    <script>

                        function initBtn(status) {
                            if (status == '0') {
                                $('#tabs').tabs({
                                    tools: [{
                                        text: '保存',
                                        iconCls: 'icon-save',
                                        handler: function () {
                                            save('save');
                                        }
                                    }, {
                                        text: '完成',
                                        iconCls: 'icon-ok',
                                        handler: function () {
                                            $.messager.confirm('提示', '提交后无法再次编辑，确定要提交吗?',
                                                function (r) {
                                                    if (r) {
                                                        save('submit');
                                                    }
                                                });
                                        }
                                    }]
                                })
                            } else {
                                $('#tabs').tabs({
                                    tools: null
                                })
                            }
                        }

                        /**
                         *  按条件查询列表
                         */
                        function selectList() {
                            var startTime = $('#startTime').datebox('getValue')
                            var endTime = $('#endTime').datebox('getValue')
                            var status = $('#queryStatus').combobox('getValue');
                            var dg = $('#dg');
                            dg.datagrid('enableFilter');
                            dg.datagrid('load', {
                                startTime: startTime ? startTime : '',
                                endTime: endTime ? endTime : '',
                                status: status ? status : ''
                            });
                        }

                        function bindgrid() {
                            var startTime = $('#startTime').datebox('getValue')
                            var endTime = $('#endTime').datebox('getValue')
                            var status = $('#queryStatus').combobox('getValue');
                            $('#dg').datagrid({
                                title: '',
                                queryParams: {
                                    startTime: startTime,
                                    endTime: endTime,
                                    status: status
                                },
                                url: "oos/corrective/action/selectList",
                                iconCls: 'icon-application',
                                width: getWidth(0.98),
                                height: 400,
                                nowrap: true,
                                filterDelay: 0,
                                rownumbers: true,
                                animate: false,
                                collapsible: false,
                                clientPaging: false,
                                remoteFilter: true,
                                singleSelect: true,
                                pagination: true,
                                remoteSort: true,
                                frozenColumns: [[]],
                                columns: [
                                    [
                                        {
                                            field: 'corId',
                                            title: '预防纠正id',
                                            sortable: true,
                                            hidden: true,
                                            formatter: function (val, rec) {
                                                return val ? unescape(val) : '';
                                            }
                                        }, {
                                            field: 'corNum',
                                            title: '编码',
                                            sortable: true,
                                            formatter: function (val, rec, index) {
                                                return '<a style="text-decoration: none;" href="javascript:void(0)" onclick="detail(' + index +
                                                    ')">' + (val ? val : '') + '</a>'
                                            }
                                        }, {
                                            field: 'corTitle',
                                            title: '预防纠正标题',
                                            sortable: true,
                                            formatter: function (val, rec) {
                                                return val ? unescape(val) : '';
                                            }
                                        }, {
                                            field: 'status',
                                            title: '状态',
                                            sortable: true,
                                            formatter: function (val, rec) {
                                                return val == '1' ? '已完成' : '待完成';
                                            }
                                        }, {
                                            field: 'createId',
                                            title: '创建人id',
                                            sortable: true,
                                            hidden: true,
                                            formatter: function (val, rec) {
                                                return val ? unescape(val) : '';
                                            }
                                        }, {
                                            field: 'createTime',
                                            title: '创建时间',
                                            sortable: true,
                                            formatter: function (val, rec) {
                                                return val ? unescape(val) : '';
                                            }
                                        }, {
                                            field: 'updateId',
                                            title: '更新人id',
                                            sortable: true,
                                            hidden: true,
                                            formatter: function (val, rec) {
                                                return val ? unescape(val) : '';
                                            }
                                        }, {
                                            field: 'updateTime',
                                            title: '更新时间',
                                            sortable: true,
                                            formatter: function (val, rec) {
                                                return val ? unescape(val) : '';
                                            }
                                        }]],
                                toolbar: [{
                                    text: '增加',
                                    iconCls: 'icon-add',
                                    handler: function () {
                                        $('#dg').datagrid('clearSelections');
                                        $('#fm').form('clear');
                                        initSuperviseDataGrid([])
                                        $('#add').window('open');
                                        initFile([]);
                                        initBtn('0');
                                        $('#tabs').tabs('select', 0)
                                    }
                                },
                                    '-',
                                {
                                    text: '编辑',
                                    iconCls: 'icon-edit',
                                    handler: function () {
                                        //编辑
                                        var row = $('#dg').datagrid('getSelected');
                                        if (row) {
                                            detailAjax(row.corId)
                                        } else {
                                            $.messager.alert('消息', '请选中一条数据');
                                        }
                                    }
                                },
                                    '-',
                                {
                                    text: '删除',
                                    iconCls: 'icon-cancel',
                                    handler: function () {
                                        var row = $('#dg').datagrid('getSelected');
                                        if (row) {
                                            if (row.status > 0) {
                                                $.messager.alert('消息', '已提交，不可删除！');
                                                return;
                                            }
                                            $.messager.confirm('提示', '该操作会将此项下所有行动项及附件删除，是否确定?', function (r) {
                                                if (r) {
                                                    del(row);
                                                }
                                            });
                                        } else {
                                            $.messager.alert('消息', '请选中一条数据');
                                        }
                                    }
                                }],
                                onLoadSuccess: function () {
                                },
                                onDblClickRow: function () {
                                }
                            });
                            $('#dg').datagrid('enableFilter');
                        }


                        // 导出为Excel
                        function exportList() {
                            let startTime = $('#startTime').datebox('getValue')
                            let endTime = $('#endTime').datebox('getValue')
                            let status = $('#status').combobox('getValue')
                            var form = [];
                            form.push('startTime=' + (startTime ? startTime : ''));
                            form.push('endTime=' + (endTime ? endTime : ''));
                            form.push('status=' + (status ? status : ''));
                            let url = "oos / corrective / action/export"
                            let xhr = new XMLHttpRequest()
                            xhr.open('POST', url, true)
                            xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                            xhr.setRequestHeader('token', localStorage.getItem('token'));
                            xhr.setRequestHeader('userType', localStorage.getItem('userType'));
                            xhr.responseType = 'blob'
                            xhr.onload = function () {
                                if (this.status == 200) {
                                    let blob = this.response
                                    let reader = new FileReader()
                                    reader.readAsDataURL(blob)
                                    reader.onload = function (e) {
                                        let a = document.createElement('a')
                                        a.download = '询价供应商' + new Date().toLocaleDateString() + '-' + new Date().toLocaleTimeString() + '.xlsx'
                                        a.href = e.target.result
                                        $('body').append(a)
                                        a.click()
                                        $(a).remove()
                                    }
                                }
                            }
                            xhr.send(form.join('&'))
                        }
                    </script>
                    <style scoped="scoped">
                        .textbox {
                            height: 20px;
                            margin: 0;
                            padding: 0 2px;
                            box-sizing: content-box;
                        }

                        /*.table tr {
height: 15px;
}*/
                    </style>
                    <div class="query_criteria" id="query_criteria">
                        <div style="margin: 5px 0px">
                            <%-- 搜索框 --%>
                                <label style="font-size: 12px;">创建时间：</label> <input class="easyui-datebox"
                                    name="startTime" id="startTime"
                                    data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
                                    value="" style="width: 150px"> <label style="font-size: 10px;">~</label> <input
                                    class="easyui-datebox" name="endTime" id="endTime"
                                    data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
                                    style="width: 150px" /> <label
                                    style="margin-left: 20px; font-size: 12px;">状态：</label>
                                <input class="easyui-combobox" id="queryStatus" name="status" style="width: 80px;"
                                    data-options="valueField: 'value',editable:false,
						textField: 'label',panelHeight:'auto',data: [{
							label: '全部',
							value: ''
						},{
							label: '待提交',
							value: '0',
							selected:true
						},{
							label: '已提交',
							value: '1'
						}]">
                                </select> <a id="search" style="margin-left: 30px" href="javascript:void(0)"
                                    class="easyui-linkbutton" data-options="iconCls:'icon-search'"
                                    onclick="selectList()">查询</a> <a id="export" href="javascript:void(0)"
                                    class="easyui-linkbutton" data-options="iconCls:'icon-export'"
                                    onclick="exportList()">导出</a>
                        </div>

                        <table id="dg"></table>
                        <%-- 新增/编辑/详情 --%>
                            <div id="add" class="easyui-window" closed="true" modal="true" title="详细信息"
                                style="width: 930px; height: 400px; padding: 5px 5px; top: 50px;">
                                <div id="tabs" class="easyui-tabs" style="width: 885px; height: 350px">
                                    <div title="基本信息" style="padding: 5px;">
                                        <form id="fm" class="ssec-form">
                                            <table class="table">
                                                <tr>
                                                    <td>
                                                        <%-- 预防纠正id--%>
                                                            <input id="corId" type="hidden" name="corId" />
                                                            <div class="ssec-label">预防编码：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal">
                                                            <input id="corNum" name="corNum" class="easyui-textbox"
                                                                data-options="required:false,readonly:true" />
                                                        </div>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <div class="ssec-label">预防纠正标题：</div>
                                                    </td>
                                                    <td>
                                                        <div class="ssec-text normal">
                                                            <input id="corTitle" name="corTitle" class="easyui-textbox"
                                                                data-options="required:true" />
                                                        </div>
                                                    </td>
                                                </tr>
                                            </table>
                                        </form>
                                    </div>
                                    <div title="督办项" style="padding: 5px;">
                                        <table id="supervise"></table>
                                    </div>
                                    <%-- <div title="附件" style="padding: 5px;">
                                        <table>
                                            <tr>
                                                <td colspan="3"><input type="button" id="uploadbtn" value="选择文件..." />
                                                    <input type="file" id="uploadpicker" accept=""
                                                        onchange="changeFile()" multiple style="display: none;" />
                                                    <span>（文件名称不能包含斜杠、空格、&、#等特殊字符）</span>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td><label style="width: 40%; text-align: right;">附件下载：</label>
                                                    <ul id="checkfileList"></ul>
                                                </td>
                                            </tr>
                                        </table>
                                </div>--%>
                            </div>
                    </div>
                    <%-- 行动项详情 --%>
                        <div id="supviseDetaillWindow" class="easyui-window" closed="true" modal="true" title="督办项详情"
                            style="width: 930px; height: 400px; padding: 5px 5px; top: 50px;">
                            <div id="supviseTabs" class="easyui-tabs" data-options="selected:0"
                                style="width: 885px; height: 350px">
                                <div title="督办项详情" style="padding: 5px;">
                                    <table>
                                        <input id="supId" name="supId" type="hidden" />
                                        <tr>
                                            <td>
                                                <div class="ssec-label">计划完成时间：</div>
                                            </td>
                                            <td>
                                                <div class="ssec-text normal">
                                                    <input id="planCompleteDate" name="planCompleteTime"
                                                        class="easyui-textbox" data-options="readonly:true" />
                                                </div>
                                            </td>
                                            <td>
                                                <div class="ssec-label">实际完成时间：</div>
                                            </td>
                                            <td>
                                                <div class="ssec-text normal">
                                                    <input id="realCompleteDate" name="realCompleteDate"
                                                        class="easyui-textbox" data-options="readonly:true" />
                                                </div>
                                            </td>
                                            <td>
                                                <div class="ssec-label">责任部门名称：</div>
                                            </td>
                                            <td>
                                                <div class="ssec-text normal">
                                                    <input id="dutyDeptName" name="dutyDeptName" class="easyui-textbox"
                                                        data-options="readonly:true" />
                                                </div>
                                            </td>
                                        </tr>
                                        <tr>

                                            <td>
                                                <div class="ssec-label">责任人：</div>
                                            </td>
                                            <td>
                                                <div class="ssec-text normal">
                                                    <input id="dutyPersonName" name="dutyPersonName"
                                                        class="easyui-textbox" data-options="readonly:true" />
                                                </div>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <div class="ssec-label">存在问题：</div>
                                            </td>
                                            <td colspan="4">
                                                <div class="ssec-text normal">
                                                    <input id="problem" name="problem" class="easyui-textbox"
                                                        style="width:250px;height:60px"
                                                        data-options="readonly:true,multiline:true" />
                                                </div>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <div class="ssec-label">原因分析：</div>
                                            </td>
                                            <td colspan="4">
                                                <div class="ssec-text normal">
                                                    <input id="cause" name="cause" class="easyui-textbox"
                                                        style="width:250px;height:60px"
                                                        data-options="readonly:true,multiline:true" />
                                                </div>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <div class="ssec-label">预防纠正措施：</div>
                                            </td>
                                            <td colspan="4">
                                                <div class="ssec-text normal">
                                                    <input id="action" name="action" class="easyui-textbox"
                                                        style="width:250px;height:60px"
                                                        data-options="readonly:true,multiline:true" />
                                                </div>
                                            </td>
                                        </tr>


                                        <tr>
                                            <td>
                                                <div class="ssec-label">整改描述：</div>
                                            </td>
                                            <td colspan="5">
                                                <div class="ssec-text normal">
                                                    <input id="reformStatus" name="reformStatus" class="easyui-textbox"
                                                        style="width:350px;height:60px"
                                                        data-options="readonly:true,multiline:true" />
                                                </div>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                                <div title="附件" style="padding: 5px;">
                                    <table>
                                        <tr>
                                            <td><label style="width: 40%; text-align: right;">附件：</label>
                                                <ul id="supviseFileList"></ul>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                            </div>
                        </div>
                        <div id="historyWindow" class="easyui-window" closed="true" modal="true" title="修改记录"
                            style="width: 930px; height: 400px; padding: 5px 5px; top: 50px;">
                            <table id="history"></table>
                        </div>

                        </div>
        </body>
        <script>
            var editIndex = undefined;
            var selectedSuperviseFileList = []

            // 行编辑结束
            function endEditing() {

                if (editIndex == undefined) {
                    return true
                }
                if ($('#supervise').datagrid('validateRow', editIndex)) {
                    $('#supervise').datagrid('endEdit', editIndex);
                    editIndex = undefined;
                    return true;
                } else {
                    $.messager.alert('提示', '有未填写数据!')
                    return false;
                }
            }

            /**
             * 初始化行动项明细表
             * @param data
             */
            function initSuperviseDataGrid(data) {
                let supervise = $('#supervise')
                supervise.datagrid(
                    {
                        data: data,
                        iconCls: 'icon-application',
                        clientPaging: true,
                        remoteFilter: false,
                        filterDelay: 0,
                        width: 850,
                        height: 300,
                        nowrap: true,
                        rownumbers: true,
                        animate: false,
                        collapsible: false,
                        singleSelect: true,
                        pagination: false,
                        frozenColumns: [[]],
                        columns: [
                            [
                                {
                                    field: 'supId',
                                    title: '督办id',
                                    sortable: true,
                                    hidden: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                },
                                {
                                    field: 'corId',
                                    title: '主id',
                                    sortable: true,
                                    hidden: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'problem',
                                    title: '存在问题',
                                    sortable: true,
                                    width: 150,
                                    editor: {
                                        type: 'textbox',
                                        options: {
                                            required: true
                                        }
                                    },
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '--';
                                    }
                                }, {
                                    field: 'dutyDeptCode',
                                    title: '责任部门',
                                    sortable: true,
                                    width: 200,
                                    editor: {
                                        type: 'combotree',
                                        options: {
                                            editable: false,
                                            required: true,
                                            url: 'DeptManage/DeptListJson_combobox?deptid=982ce640-1567-4b68-a324-4aa5bd1f1804'
                                        }
                                    },
                                    formatter: function (val, rec) {
                                        return val ? unescape(rec.dutyDeptName) : '--'
                                    }
                                }, {
                                    field: 'cause',
                                    title: '原因分析',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        let valTem = val ? val : '--'
                                        return "<a style=\" color: blue;text-decoration: none; margin-left: 30px;\" href=\"javascript:void(0)\" onclick=\"getSupviseDetail('" + rec.supId
                                            + "')\">" + valTem + "</a>"
                                    }
                                }, {
                                    field: 'action',
                                    title: '预防纠正措施',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '--';
                                    }
                                }, {
                                    field: 'dutyDeptName',
                                    title: '责任部门名称',
                                    sortable: true,
                                    hidden: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '--';
                                    }
                                }, {
                                    field: 'dutyPersonName',
                                    title: '责任人名称',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '--';
                                    }
                                }, {
                                    field: 'dutyPersonCode',
                                    title: '责任人账号',
                                    sortable: true,
                                    hidden: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '--';
                                    }
                                }, {
                                    field: 'dutyPersonId',
                                    title: '责任人id',
                                    sortable: true,
                                    hidden: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '--';
                                    }
                                }, {
                                    field: 'planCompleteDate',
                                    title: '计划完成日期',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '--';
                                    }
                                }, {
                                    field: 'realCompleteDate',
                                    title: '实际完成日期',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '--';
                                    }
                                }, {
                                    field: 'reformStatus',
                                    title: '整改效果',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '--';
                                    }
                                }, {
                                    field: 'createTime',
                                    title: '创建日期',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '--';
                                    }
                                }, {
                                    field: 'updateTime',
                                    title: '更新时间',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '--';
                                    }
                                }, {
                                    field: 'status',
                                    title: '状态',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val == '1' ? '已完成' : '待完成';
                                    }
                                }
                            ]
                        ],
                        toolbar: [
                            {
                                text: '新增',
                                iconCls: 'icon-add',
                                handler: function () {
                                    $('#supervise').datagrid('appendRow', {});
                                }
                            }, '-',
                            {
                                text: '移除',
                                iconCls: 'icon-remove',
                                handler: function () {
                                    let row = $('#supervise').datagrid('getSelected');
                                    if (row) {
                                        $.messager.confirm('提示', '本条数据已输入的整改描述及附件会被删除，确定要删除吗?',
                                            function (r) {
                                                if (r) {
                                                    // 获取索引
                                                    let index = $('#supervise').datagrid('getRowIndex', row)
                                                    // 删除前结束编辑
                                                    $('#supervise').datagrid('endEdit', editIndex);
                                                    editIndex = undefined;
                                                    // 删除行
                                                    $('#supervise').datagrid('deleteRow', index)
                                                    // 删除数据库的该数据
                                                    if (row.supId) {
                                                        $.ajax({
                                                            type: "delete",
                                                            dataType: "json",
                                                            url: 'oos/corrective/supervise/delete?supId=' + row.supId,
                                                            success: function (data) {
                                                                $.messager.alert('消息', data.msg);
                                                            },
                                                            error: function (XMLHttpRequest, textStatus,
                                                                errorThrown) {
                                                                $.messager.alert('消息', errorThrown);
                                                            }
                                                        })
                                                    }
                                                }
                                            });
                                    } else {
                                        $.messager.alert('消息', '请选中一条要删除的数据');
                                    }
                                }
                            }, {
                                text: '退回',
                                iconCls: 'icon-back',
                                handler: function () {
                                    let selectd = $('#supervise').datagrid('getSelected')
                                    if (selectd) {
                                        // 如果状态为1，则将该行动项状态变为0
                                        if (selectd.status == '1') {
                                            $.messager.confirm('提示', '确定要退回吗?',
                                                function (r) {
                                                    if (r) {
                                                        backUp(selectd)
                                                    }
                                                });

                                        } else {
                                            $.messager.alert('提示', '该督办项进行中，无需退回')
                                            return
                                        }
                                    } else {
                                        $.messager.alert('提示', '请选择要退回的记录')
                                        return
                                    }
                                }
                            }],
                        onEndEdit: function (index, row) {
                            var ed = $(this).datagrid('getEditor', {
                                index: index,
                                field: 'dutyDeptCode'
                            });
                            row.dutyDeptName = $(ed.target).combobox('getText');
                        },
                        onClickCell: function (rowIndex, field, value) {
                            if (editIndex != rowIndex) {
                                if (endEditing()) {
                                    $('#supervise').datagrid('selectRow', rowIndex)
                                        .datagrid('beginEdit', rowIndex);
                                    var ed = $('#supervise').datagrid('getEditor', { index: rowIndex, field: field });
                                    if (ed) {
                                        ($(ed.target).data('textbox') ? $(ed.target).textbox('textbox') : $(ed.target)).focus();
                                    }
                                    editIndex = rowIndex;
                                } else {
                                    setTimeout(function () {
                                        $('#supervise').datagrid('selectRow', editIndex);
                                    }, 0);
                                }
                            }
                        },
                        onLoadSuccess: function () {
                        },
                        onDblClickRow: function () {
                        }
                    });
            }

            /**
             * 获取行动项详情
             * 行动项id
             * @param supId
             */
            function getSupviseDetail(supId) {
                if (!supId || 'undefined' == supId) {
                    return
                }
                $.ajax({
                    type: 'get',
                    url: 'oos/corrective/supervise/selectInfor?supId=' + supId,
                    dataType: 'json',
                    success: function (data) {
                        if (data.code == 60200) {
                            let supvise = data.data
                            $('#supId').val(supId)
                            // 问题
                            $('#problem').textbox('setValue', supvise.problem)
                            // 原因
                            $('#cause').textbox('setValue', supvise.cause)
                            // 预防措施
                            $('#action').textbox('setValue', supvise.action)
                            $('#planCompleteDate').textbox('setValue', supvise.planCompleteDate)
                            $('#realCompleteDate').textbox('setValue', supvise.realCompleteDate)
                            $('#dutyDeptName').textbox('setValue', supvise.dutyDeptName)
                            $('#dutyPersonName').textbox('setValue', supvise.dutyPersonName)
                            $('#reformStatus').textbox('setValue', supvise.reformStatus)
                            getSupviseFileList(supvise.supId)
                            $('#supviseDetaillWindow').window('open')
                            $('#supviseTabs').tabs('select', 0)
                        } else {
                            $.messager.alert('消息', data.msg);
                        }
                    }
                })
            }

            function detail(index) {
                const rows = $('#dg').datagrid('getRows')
                let row = rows[index]
                if (!row) {
                    $.messager.error('错误', '请至少选择一行数据')
                    return
                }
                detailAjax(row.corId)
            }

            function detailAjax(corId) {
                $.ajax({
                    type: 'get',
                    url: 'oos/corrective/action/selectInfor?corId=' + corId,
                    dataType: 'json',
                    success: function (data) {
                        if (data.code == 60200) {
                            let model = data.data
                            getFileList(model.corId)
                            setDetail(model)
                            setTabToolBar(model)
                        } else {
                            $.messager.alert('消息', data.msg);
                        }
                    }
                })
                $('#add').window('open')
                $('#tabs').tabs('select', 0)
            }

            function setDetail(model) {
                if (!model) {
                    return
                }
                $('#corId').val(model.corId)
                $('#corNum').textbox('setValue', model.corNum)
                $('#corTitle').textbox('setValue', model.corTitle)
                const supervises = model.supervises
                initSuperviseDataGrid(supervises)

            }

            function setTabToolBar(row) {
                if ('0' == row.status) {
                    $('#tabs').tabs({
                        tools: [{
                            text: '保存',
                            iconCls: 'icon-save',
                            handler: function () {
                                save('save');
                            }
                        }, {
                            text: '完成',
                            iconCls: 'icon-ok',
                            handler: function () {
                                $.messager.confirm('提示', '点击完成后无法再次编辑，确定要提交吗?',
                                    function (r) {
                                        if (r) {
                                            save('submit')
                                        }
                                    });
                            }
                        }]
                    })
                    $('#supervise').datagrid({
                        toolbar: [
                            {
                                text: '新增',
                                iconCls: 'icon-add',
                                handler: function () {
                                    $('#supervise').datagrid('appendRow', {});
                                }
                            }, '-',
                            {
                                text: '移除',
                                iconCls: 'icon-remove',
                                handler: function () {
                                    let row = $('#supervise').datagrid('getSelected');
                                    if (row) {
                                        $.messager.confirm('提示', '本条数据已输入的整改描述及附件会被删除，确定要删除吗?',
                                            function (r) {
                                                if (r) {
                                                    // 获取索引
                                                    let index = $('#supervise').datagrid('getRowIndex', row)
                                                    // 删除前结束编辑
                                                    $('#supervise').datagrid('endEdit', editIndex);
                                                    editIndex = undefined;
                                                    // 删除行
                                                    $('#supervise').datagrid('deleteRow', index)
                                                    // 删除数据库的该数据
                                                    if (row.supId) {
                                                        $.ajax({
                                                            type: "delete",
                                                            dataType: "json",
                                                            url: 'oos/corrective/supervise/delete?supId=' + row.supId,
                                                            success: function (data) {
                                                                $.messager.alert('消息', data.msg);
                                                            },
                                                            error: function (XMLHttpRequest, textStatus,
                                                                errorThrown) {
                                                                $.messager.alert('消息', errorThrown);
                                                            }
                                                        })
                                                    }
                                                }
                                            });
                                    } else {
                                        $.messager.alert('消息', '请选中一条要删除的数据');
                                    }
                                }
                            }, '-',
                            {
                                text: '退回',
                                iconCls: 'icon-back',
                                handler: function () {
                                    let selectdImp = $('#supervise').datagrid('getSelected')
                                    if (selectdImp) {
                                        // 如果状态为1，则将该行动项状态变为0
                                        if (selectdImp.status == '1') {
                                            $.messager.confirm('提示', '确定要退回吗?',
                                                function (r) {
                                                    if (r) {
                                                        backUp(selectdImp)
                                                    }
                                                });

                                        } else {
                                            $.messager.alert('提示', '该整改项进行中，无需退回')
                                            return
                                        }
                                    } else {
                                        $.messager.alert('提示', '请选择要退回的记录')
                                        return
                                    }
                                }
                            }, '-',
                            {
                                text: '修改记录',
                                iconCls: 'icon-large-smartart',
                                handler: function () {
                                    let row = $('#supervise').datagrid('getSelected');
                                    if (row) {
                                        // 结束编辑
                                        $('#supervise').datagrid('endEdit', editIndex);
                                        editIndex = undefined;
                                        showHistory(row)
                                    } else {
                                        $.messager.alert('消息', '请选中一条要查看的数据。');
                                    }
                                }
                            }
                        ]
                    });
                } else {
                    $('#tabs').tabs({
                        tools: ''
                    })
                    $('#supervise').datagrid({
                        toolbar: [
                            {
                                text: '修改记录',
                                iconCls: 'icon-large-smartart',
                                handler: function () {
                                    let row = $('#supervise').datagrid('getSelected');
                                    if (row) {
                                        // 结束编辑
                                        $('#supervise').datagrid('endEdit', editIndex);
                                        editIndex = undefined;
                                        showHistory(row)

                                    } else {
                                        $.messager.alert('消息', '请选中一条要查看的数据');
                                    }
                                }
                            }
                        ]
                    })
                }
            }

            // 退回整改项
            function backUp(obj) {
                if (!obj) return
                $.ajax({
                    type: 'GET',
                    url: 'oos/corrective/supervise/back?supId=' + obj.supId,
                    success: function (data) {
                        if (data.code != 60200) {
                            $.messager.alert('消息', data.msg);
                            return
                        } else {
                            $('#add').window('close');
                            detailAjax(obj.corId)
                            $('#tabs').tabs('select', 1)
                            $.messager.alert('消息', data.msg);
                        }

                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        $.messager.alert('消息', errorThrown);
                    }
                })

            }

            function showHistory(obj) {
                let supId = obj.supId
                if (!supId || 'undefined' == supId) {
                    return
                }
                $('#history').datagrid({
                    title: '历史记录',
                    queryParams: {
                        supId: supId
                    },
                    url: "oos/corrective/supervise/history/selectList",
                    iconCls: 'icon-application',
                    width: getWidth(0.98),
                    height: 415,
                    nowrap: true,
                    filterDelay: 0,
                    rownumbers: true,
                    animate: false,
                    collapsible: false,
                    clientPaging: false,
                    remoteFilter: true,
                    singleSelect: true,
                    pagination: true,
                    remoteSort: true,
                    frozenColumns: [[]],
                    columns: [[{
                        field: 'hisId',
                        title: '记录id',
                        sortable: true,
                        hidden: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : '';
                        }
                    }, {
                        field: 'supId',
                        title: '督办id',
                        sortable: true,
                        hidden: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : '';
                        }
                    }, {
                        field: 'corId',
                        title: '问题id',
                        sortable: true,
                        hidden: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : '';
                        }
                    }, {
                        field: 'recordTime',
                        title: '记录时间',
                        sortable: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : '';
                        }
                    }, {
                        field: 'problem',
                        title: '存在问题',
                        sortable: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : '';
                        }
                    }, {
                        field: 'cause',
                        title: '原因分析',
                        sortable: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : '';
                        }
                    }, {
                        field: 'action',
                        title: '预防纠正措施',
                        sortable: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : '';
                        }
                    }, {
                        field: 'dutyDeptName',
                        title: '责任部门名称',
                        sortable: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : '';
                        }
                    }, {
                        field: 'dutyDeptCode',
                        title: '责任部门code',
                        sortable: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : '';
                        }
                    }, {
                        field: 'dutyPersonName',
                        title: '责任部门负责人名称',
                        sortable: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : '';
                        }
                    }, {
                        field: 'dutyPersonCode',
                        title: '责任部门账号',
                        sortable: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : '';
                        }
                    }, {
                        field: 'dutyPersonId',
                        title: '责任人id',
                        sortable: true,
                        hidden: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : '';
                        }
                    }, {
                        field: 'planCompleteDate',
                        title: '计划完成日期',
                        sortable: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : '';
                        }
                    }, {
                        field: 'realCompleteDate',
                        title: '实际完成日期',
                        sortable: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : '';
                        }
                    }, {
                        field: 'reformStatus',
                        title: '整改效果',
                        sortable: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : '';
                        }
                    }, {
                        field: 'createId',
                        title: '创建人id',
                        sortable: true,
                        hidden: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : '';
                        }
                    }, {
                        field: 'createTime',
                        title: '创建日期',
                        sortable: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : '';
                        }
                    }, {
                        field: 'updateId',
                        title: '更新人id',
                        sortable: true,
                        hidden: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : '';
                        }
                    }, {
                        field: 'updateTime',
                        title: '更新时间',
                        sortable: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : '';
                        }
                    }]],
                    toolbar: [],
                    onLoadSuccess: function () {
                    },
                    onDblClickRow: function () {
                    }
                });
                $('#history').datagrid('enableFilter');

                $('#historyWindow').window('open')

            }

            /**
             * 取得该行动项所属的文件列表
             * @param row
             */
            function getSupviseFileList(row) {
                $.ajax({
                    type: "post",
                    url: "file/getFileList",
                    data: {
                        fileTable: "oos_corrective_supervise",
                        fileRow: row
                    },
                    success: function (data) {
                        const dataArray = eval(data);
                        initSupviseFile(dataArray);
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        $.messager.alert('消息', errorThrown);
                    }
                });
            }

            /**
             *初始化各行动项的附件列表
             */
            function initSupviseFile(dataArray) {
                $("#supviseFileList").empty();
                // 			sselectedFileNameList = [];
                selectedSuperviseFileList = [];
                dataArray
                    .forEach(function (e, i, a) {
                        $("#supviseFileList")
                            .append(
                                "<li class=\"supviseFileinfo\">"
                                + "<a style=\" color: blue; margin-left: 30px;\" href=\"javascript:void(0)\" onclick=\"downloadFile('" + e.FILE_NAME + "','"
                                + e.FILE_ID
                                + "')\">"
                                + e.FILE_NAME
                                + "</a>"
                                + "</li>");
                        // 						sselectedFileNameList.push(e.FILE_NAME);
                        // AddsupviseMoushover();
                    });
            }

            /**
             * //添加鼠标经过事件，鼠标划过时显示“删除”--supvise
             * @constructor
             */
            function AddsupviseMoushover() {
                $(".supviseFileinfo").hover(function () {
                    $(this).find("a").last().css("display", "");
                }, function () {
                    $(this).find("a").last().css("display", "none");
                });
            }
        </script>

        </html>